<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <link href="/mp/common/layui/css/layui.css" rel="stylesheet">
    <link href="./css/mp.css?v=21212" rel="stylesheet">
</head>
<body>
    
    <!-- 群发多条图文 -->
    <div id="pushManyText" class="layui-body" style="margin-left: 10%;margin-top: 2%">
        <div class="page_content">
            <div id="tb">
                <input id="body" name="title" class="layui-input" style="width: 20%;display: inline;margin-right: 1%" placeholder="请输入标题" data-locale="headline_info">
                <input id="bodyImgUrl" name="img" class="layui-input" style="width: 20%;display: inline;margin-right: 1%" placeholder="请输入图片url" data-locale="pushbodyImgUrl_info">
                <input id="bodyHtmlUrl" name="url" class="layui-input" style="width: 20%;display: inline;margin-right: 1%" placeholder="请输入网页url" data-locale="bodyHtmlUrl">
            </div>
            <button onclick="DoubleImgText.addDoubleImgText()" class="layui-btn" type="button" style="margin-top: 1%" data-locale="add">新增</button>
            <button id="groupSendDoubleImgText_btn"  class="layui-btn" type="submit" style="margin-top: 1%" data-locale="textbody_btn">群发</button>
        
            
            <!-- 示例 -->
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md10" style="margin-top: 5%;height: 2%" >
                    <h1 data-locale="example">示例</h1>
                    <img alt="" style="margin-left: 20%" src="./images/pushMany.png">
                </div>
            </div>

        </div>
    </div>



    <script type="text/javascript" src="/mp/common/layui/layui.all.js"></script>
    <script type="text/javascript" src="/mp/common/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/mp/common/jquery/jquery.md5.js"></script>

    <!-- i18n国际化 -->
    <script type="text/javascript" src="./common/i18n/jquery.i18n.properties.js"></script>

    <script type="text/javascript" src="/mp/js/mp_commons.js"></script>
    <script type="text/javascript" src="./js/mp_httpApi.js"></script>

    <script type="text/javascript">

        //多图文数量
        var doubleImgTextNum = 1;

        var DoubleImgText = {
            //群发多图文
            //$('#groupSendDoubleImgText_btn').on('click',function(){
            groupSendDoubleImgText : function(){

                var bodyVal = $("#body").val();
                var bodyHtmlUrlVal = $("#bodyHtmlUrl").val();
                var bodyImgUrlVal = $("#bodyImgUrl").val();

                if(null == bodyVal || "" == bodyVal || undefined == bodyVal){
                    layui.layer.alert(mpLanguage.getLanguageName('headline_info'));
                    return;
                }
                if(null == bodyImgUrlVal || "" == bodyImgUrlVal || undefined == bodyImgUrlVal){
                    layui.layer.alert(mpLanguage.getLanguageName('pushbodyImgUrl_info'));
                    return;
                }
                if(null == bodyHtmlUrlVal || "" == bodyHtmlUrlVal || undefined == bodyHtmlUrlVal){
                    layui.layer.alert(mpLanguage.getLanguageName('bodyHtmlUrl'));
                    return;
                }
                var title = new Array();
                title.push(bodyVal);
                var url = new Array();
                url.push(bodyHtmlUrlVal);
                var img = new Array();
                img.push(bodyImgUrlVal);

                for(var j=2; j<=doubleImgTextNum; j++){
                    var fVal = $("#f"+j).val();
                    var dVal = $("#d"+j).val();
                    var cVal = $("#c"+j).val();
                    if( undefined == fVal){
                        continue;
                    }
                    if(null == fVal || "" == fVal || undefined == fVal){
                        layui.layer.alert(mpLanguage.getLanguageName('headline_info'));
                        return;
                    }
                    if(null == cVal || "" == cVal || undefined == cVal){
                        layui.layer.alert(mpLanguage.getLanguageName('pushbodyImgUrl_info'));
                        return;
                    }
                    if(null == dVal || "" == dVal || undefined == dVal){
                        layui.layer.alert(mpLanguage.getLanguageName('bodyHtmlUrl'));
                        return;
                    }

                    title.push($("#f"+j).val());
                    url.push($("#d"+j).val());
                    img.push($("#c"+j).val());
                }

                mpCommon.invokeByArray({
                    url : '/mp/manyToAll',
                    data : {
                        title:title,
                        url:url,
                        img:img
                    },
                    success : function(result) {
                        if (result.resultCode == 1) {

                            $("#body").val("");
                            $("#bodyImgUrl").val("");
                            $("#bodyHtmlUrl").val("");
                            for(var j=2;j<=doubleImgTextNum;j++){

                                $("#f"+j).remove();
                                $("#d"+j).remove();
                                $("#c"+j).remove();
                                $("#delete"+j).remove();
                            }
                            title=[];
                            url=[];
                            img=[];
                            doubleImgTextNum = 1;// 重置
                            layui.layer.alert(mpLanguage.getLanguageName('successful_mass'));
                        } else {
                            alert(mpLanguage.getLanguageName('mass_failure'));
                        }
                    },
                    error : function(result) {
                        layui.layer.alert(mpLanguage.getLanguageName('mass_failure'));
                    }
                });
            },
            addDoubleImgText : function(){

                doubleImgTextNum++;
                var divId="manyDiv"+doubleImgTextNum;
                var table= "<div id='"+divId+"' style='margin-top: 1%'>"
                         +      "<input id='f"+doubleImgTextNum+"' name='title' class='layui-input' style='width: 20%;display: inline;margin-right: 1.3%' placeholder='"+ mpLanguage.getLanguageName('headline_info') +"'>"
                         +     "<input id='c"+doubleImgTextNum+"' name='img' class='layui-input' style='width: 20%;display: inline;margin-right: 1.3%' placeholder='请输入图片url'>"
                         +     "<input id='d"+doubleImgTextNum+"' name='url' class='layui-input' style='width: 20%;display: inline;margin-right: 1.3%' placeholder='请输入网页url'>"
                         +     "<button id='delete"+doubleImgTextNum+"' onclick='DoubleImgText.removeDoubleImgText("+divId+")' class='layui-btn' type='button' style=''>删除</button>"
                         + "</div>";

                $("#tb").append(table);
            },
            removeDoubleImgText : function(id){
                id.remove();
                doubleImgTextNum--;
            },

        };

        $('#groupSendDoubleImgText_btn').on('click',function(){
            DoubleImgText.groupSendDoubleImgText();
        });


    </script>



</body>
</html>
